/**
 * @description 登录JS
 * @author 赵子靖
 * @since 2017-12-12
 */
var Login = function() {
    var t = {
        path :'',
        init : function() {
            t.initView();
            t.initEvent();
        },
        initView : function() {
            
        },
        initEvent : function() {
            
        },
        //登录
        doLogin:function(){
            var account = $("#account").val();
            var password = $("#password").val();
            if(Util.isEmpty(account)){
                $("#accountSpan").html("请输入登录账号。");
                $("#account").focus();
                return;
            }
            $("#accountSpan").html("");
            if(Util.isEmpty(password)){
                $("#passwordSpan").html("请输入登录密码。");
                $("#password").focus();
                return;
            }
            $("#passwordSpan").html("");
            
            $.ajax({
                type:"POST",
                url:t.path+"/login/doMobileLogin.do",
                dataType:"json",
                data:{
                    account:account,
                    password:password
                },
                async: false,
                cache:false,
                success:function(data){
                    if(data.success){
                        //登录成功跳转首页
                        window.location.href=t.path+"/mobile/index.do";
                    }else{
                        alert(data.msg);
                        $("#passwordSpan").html(data.msg);
                    }
                }
            });
        },
        //注册
        register:function(){
            var mobile = $("#mobile").val();
            var password = $("#password").val();
            var confirmPassword = $("#confirmPassword").val();
            if(Util.isEmpty(mobile)){
                $("#tipSpan").html("请输入手机号码。");
                $("#mobile").focus();
                return;
            }
            $("#tipSpan").html("");
            if(Util.isEmpty(password)){
                $("#tipSpan").html("请输入密码。");
                $("#password").focus();
                return;
            }
            $("#tipSpan").html("");
            if(Util.isEmpty(confirmPassword)){
                $("#tipSpan").html("请输入确认密码。");
                $("#confirmPassword").focus();
                return;
            }
            $("#tipSpan").html("");
            if(password!=confirmPassword){
                $("#tipSpan").html("两次输入的密码不一致。");
                $("#confirmPassword").focus();
                return;
            }
            $("#tipSpan").html("");
            
            $.ajax({
                type:"POST",
                url:t.path+"/login/mobileRegister.do",
                dataType:"json",
                data:{
                    mobile:mobile,
                    password:password
                },
                async: false,
                cache:false,
                success:function(data){
                    if(data.success){
                        //登录成功跳转首页
                        window.location.href=t.path+"/login/forwardMobileLogin.do";
                    }else{
                        alert(data.msg);
                        $("#tipSpan").html(data.msg);
                    }
                }
            });
            
        }
    }
    return t;
}();